package com.lj.cms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lj.cms.entity.Banner;
import com.lj.cms.service.BannerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author luojing
 * @version 1.0
 * @date 2021/6/17 10:28
 */
@RestController
@RequestMapping("/cms/bannerAdmin")
@CrossOrigin
public class BannerAdminController {

    @Autowired
    private BannerService bannerService;

    @ApiOperation("分页查询banner")
    @GetMapping("/page/{page}/{limit}")
    public IPage<Banner> page(@PathVariable("page") Long page,@PathVariable("limit") Long limit){
        Page<Banner> bannerPage = new Page<>(page,limit);
        return bannerService.page(bannerPage, null);
    }

    @ApiOperation("新增Banner")
    @PostMapping("addBanner")
    public boolean addBanner(@RequestBody Banner banner){
        return bannerService.save(banner);
    }

    @ApiOperation("修改banner")
    @PutMapping("update")
    public boolean updateById(@RequestBody Banner banner){
        return bannerService.updateById(banner);
    }

    @ApiOperation("删除banner")
    @DeleteMapping("remove/{id}")
    public boolean remove(@PathVariable String id){
        return bannerService.removeById(id);
    }
}
